//
//  TopCategoryButton.m
//  Menu
//
//  Created by trimad on 11-11-11.
//  Copyright 2011 Trimad Group. All rights reserved.
//

#import "TopCategoryButton.h"
#import "Category.h"

@implementation TopCategoryButton

@synthesize category;
@synthesize point;
@synthesize nameLabel;

static int BUTTON_SELECTED_X = 705;
static int BUTTON_UNSELECTED_X = 695;
static int BUTTON_WIDTH = 58;
static int BUTTON_HEIGHT = 110;
static int NAME_LABEL_X = 30;
static int NAME_LABEL_Y = 0;
static int NAME_LABEL_WIDTH = 25;
static int NAME_LABEL_HEIGHT = 110;

+ (id)buttonWithType:(UIButtonType)buttonType point:(CGPoint) point category:(Category *)category {
	TopCategoryButton *categoryButton = [TopCategoryButton buttonWithType:buttonType];
	categoryButton.category = category;
	categoryButton.point = point;
	CGRect frame = CGRectMake(point.x, point.y, BUTTON_WIDTH, BUTTON_HEIGHT);
	categoryButton.frame = frame;
	
	categoryButton.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
	[categoryButton addSubview: categoryButton.nameLabel];
	[categoryButton setBackgroundImage:[UIImage imageNamed:@"default_imgBigCatagory.png"] 
					forState:UIControlStateNormal];
	
	categoryButton.nameLabel.frame = CGRectMake(NAME_LABEL_X, NAME_LABEL_Y, NAME_LABEL_WIDTH, NAME_LABEL_HEIGHT);
	categoryButton.nameLabel.text = categoryButton.category.name;
	categoryButton.nameLabel.font = [UIFont boldSystemFontOfSize:18];
	categoryButton.nameLabel.textColor = [UIColor brownColor];
	categoryButton.nameLabel.backgroundColor = [UIColor clearColor];
	categoryButton.nameLabel.numberOfLines = [categoryButton.category.name length];
	
	[categoryButton toUnselectedState];
	return categoryButton;
}

-(void)toSelectedState {
	[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveLinear 
					 animations:^{
						 CGRect frame = CGRectMake(BUTTON_SELECTED_X, self.point.y, BUTTON_WIDTH, BUTTON_HEIGHT);
						 self.frame = frame;
					 }
					 completion:nil
     ];
	
}

-(void)toUnselectedState {
	[UIView animateWithDuration:0.3f delay:0 options:UIViewAnimationOptionCurveLinear 
					 animations:^{
						 CGRect frame = CGRectMake(BUTTON_UNSELECTED_X, self.point.y, BUTTON_WIDTH, BUTTON_HEIGHT);
						 self.frame = frame;
						 
					 }
					 completion:nil
     ];
}

-(void) dealloc {
	[nameLabel release];
	[super dealloc];
}

@end
